class UserController < ApplicationController
  
  def pick_user
    @teams   = find_game
    @user    = User.all
    if session[:user] == nil
      flash[:notice] = "Please log in before you begin playing"
      redirect_to :controller => 'admin', :action => 'login'
    else
      @teams.player_one(session[:user])
    end
    @users1  = session[:user]
    @users2  = @teams.get_team(1)
    if @teams.get_team(0) != nil
      @picks1  = @users1.picks
    end
    if @teams.get_team(1) != nil
      @picks2  = @users2.picks
    end
  end
  
  def save_user
     @user = User.new(params[:user])
     if @user.save
       redirect_to :controller => 'team', :action => 'show_quarterbacks'
     else 
       render :action => 'new_user'
     end
  end
  
  def add_player_2
    @teams = find_game
    team = User.find(params[:id])
    @teams.player_two(team)
    redirect_to :action => 'pick_user'
  end
  
private

  def find_game
    unless session[:team]
      session[:team] = Team.new
    end
    session[:team]
  end  
  
end
